package com.hhh.petadopt.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hhh.petadopt.pojo.PetFound;
import com.hhh.petadopt.pojo.PetFoundVo;
import com.hhh.petadopt.service.AdminStrayService;
import com.hhh.petadopt.utils.JsonUtils;
import com.hhh.petadopt.utils.Page;

/**
 * 流浪动物管理
 * @author 杜镇声声
 *
 */
@Controller
public class AdminStrayController {
	@Autowired
	private AdminStrayService adminStrayService;
	
	@RequestMapping(value="/adminStray/stray")
	public String selectFoundList(PetFoundVo Vo,Model model) {
		//执行查询
		Page<PetFound> page = adminStrayService.selectPetPage(Vo);
		
		//将数据保存到域中
		model.addAttribute("page", page);
		//总条数
		model.addAttribute("total", page.getTotal());
		//页面搜索信息回显
		model.addAttribute("skind", Vo.getSkind());
		model.addAttribute("ssex", Vo.getSsex());
		model.addAttribute("sdate", Vo.getSdate());
		model.addAttribute("saccept", Vo.getSaccept());
		
		//返回流浪动物管理页面
		return "admin/Stray";
	}
	
	//流浪动物信息回显
	@RequestMapping(value="/AdminStray/selectStray")
	@ResponseBody
	public String selectStrayInfo(String id) {
		//执行查询
		PetFound selectStrayById = adminStrayService.selectStrayById(id);
		//将数据转换为jso格式
		String json = JsonUtils.objectToJson(selectStrayById);
		return json;
	}
	
	//确认受理
	@RequestMapping(value="/adminStray/confirmAccept")
	@ResponseBody
	public String confirmAccept(PetFound p) {
		//执行受理操作
		adminStrayService.confirmAceptP(p);
		String str = "成功!";
		String objectToJson = JsonUtils.objectToJson(str);
		return objectToJson;
	}
	
	//删除
	@RequestMapping(value="/adminStray/delstray")
	@ResponseBody
	public String delStray(String id) {
		//执行删除操作
		adminStrayService.delStrayById(id);
		String str = "成功!";
		return JsonUtils.objectToJson(str);
	}
	
	//删除多个
	@RequestMapping(value="/adminStray/delStrayss")
	@ResponseBody
	public String delStraysss(Integer[] ids) {
		
		//执行删除操作
		adminStrayService.deleteStrayByIds(ids);
		String str = "成功!";
		return JsonUtils.objectToJson(str);
	}

}
